//
//  HJBasicTableViewController.swift
//  WeiBo
//
//  Created by 韩俊 on 15/12/5.
//  Copyright © 2015年 HanJun. All rights reserved.
//

import UIKit

class HJBasicTableViewController: UITableViewController /*HJVisitorViewDelegate*/ {

    var userLogin = HJUserAccountViewModel.sharedAccount.accessToken != nil
    
    var visitorView: HJVisitorView?
    
    
    // MARK: - HJVisitorViewDelegate
//    func registerButtonDidSeleted() {
//        login()
//    }
//    
//    func loginButtonDidSeleted() {
//        login()
//    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    override func loadView() {
        
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    
    private func setupVisitorView() {
        
        visitorView = HJVisitorView()
        //visitorView?.delegate = self
        
        visitorView?.registerButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        
        
        navigationItem.leftBarButtonItem = UIBarButtonItem( title: "注册", target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem( title: "登录", target: self, action: "login")
        
        view = visitorView
    }
    
    func login() {
        
        let oauthVc = HJOAuthViewController()
        
        presentViewController(HJNavigationController(rootViewController:oauthVc), animated: true, completion: nil)
    }
    

    

    
}
